import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { assignOverrideWithHas } from '@/utils'

export const useUserStore = defineStore(
  'sv-user',
  () => {
    const userInfo = ref({})

    function clearUserInfo() {
      userInfo.value = {}
    }

    const rememberLoginForm = ref({
      username: '',
      password: '',
      rememberme: false
    })

    function setRememberLogin(form) {
      rememberLoginForm.value = assignOverrideWithHas(rememberLoginForm.value, form)
    }

    return {
      userInfo,
      clearUserInfo,
      rememberLoginForm,
      setRememberLogin
    }
  },
  {
    persist: true
  }
)
